package view;

/*
Cours :             LOG120 
Session :           Saison (hiver) 
Groupe :            01 
Projet :            Laboratoire #2
Etudiant(e)(s) :    Jeremy Moreau
                    Alexandre Richard
                    Philippe Pigeon
Code(s) perm. :     MORJ91010106
					RICA10028806 
                    PIGP08058903
Professeur :        Ghizlane El Boussaidi  
Date remise :       2012-03-010  
*/

import controller.LivraisonController;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import db.CarnetDeCommande;
import db.DataClass;
import model.Commande;

public class CommandesPretesView extends AbstractView implements ListSelectionListener, ActionListener
{	
	JList lvCommandesPretes;
	JButton btAccept;
	
	public CommandesPretesView(LivraisonController _ctrl)
	{
		super(_ctrl);
		init();
	}
	
	public void init()
	{
		setLayout(null);
		
		lvCommandesPretes = new JList(DataClass.getCarnetDeCommande().getReadyCommandes().toArray());
		lvCommandesPretes.addListSelectionListener(this);
		lvCommandesPretes.setBounds(0, 0, 180, 320);
		lvCommandesPretes.setBorder(new LineBorder(Color.BLACK));
		
		btAccept = new JButton("Accepter");
		btAccept.addActionListener(this);
		btAccept.setBounds(30, 330, 120, 24);
		
		add(btAccept);
		add(lvCommandesPretes);
		setVisible(true);
	}	
	
	public void clearSelection()
	{
		lvCommandesPretes.clearSelection();
	}

	@Override
	public void update(Observable o, Object o1) 
	{
		lvCommandesPretes.setListData( ((CarnetDeCommande)o).getReadyCommandes().toArray() );
	}

	@Override
	public void valueChanged(ListSelectionEvent lse) 
	{
		getLCtrl().updateGoogleMapView( (Commande)lvCommandesPretes.getSelectedValue() );
	}

	@Override
	public void actionPerformed(ActionEvent arg0) 
	{
		if(arg0.getSource() == btAccept)
		{
			getLCtrl().setAccepted( ((Commande) lvCommandesPretes.getSelectedValue()).getIdConfirmation() );
			lvCommandesPretes.setListData(DataClass.getCarnetDeCommande().getReadyCommandes().toArray());
		}
		
	}

	
	
}
